#import "XMRefreshBackFooter.h"


@interface XMRefreshBackFooter ()
@property (weak, nonatomic) UILabel *label;
@property (weak, nonatomic) UIActivityIndicatorView *loading;
@end


@implementation XMRefreshBackFooter
- (void)prepare {
    [super prepare];
    self.mj_h = 50;
    UILabel *label = [[UILabel alloc] init];
    label.font = [UIFont systemFontOfSize:12];
//    label.textColor = [UIColor colorWithRed:254 / 255.0 green:59 / 255.0 blue:125 / 255.0 alpha:1.0];
    label.textColor = kHEX(@"#878787");
    label.textAlignment = NSTextAlignmentCenter;
    [self addSubview:label];
    self.label = label;
    UIActivityIndicatorView *loading = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
//    loading.color = [UIColor colorWithRed:254 / 255.0 green:59 / 255.0 blue:125 / 255.0 alpha:1.0];
    loading.color = kHEX(@"#878787");
    [self addSubview:loading];
    self.loading = loading;
}
- (void)placeSubviews {
    [super placeSubviews];
    self.label.bounds = CGRectMake(0, 0, [self.label mj_textWidth], 16);
    self.label.center = CGPointMake(self.mj_w * 0.5, self.mj_h * 0.5);
    self.loading.center = CGPointMake(self.mj_w / 2 - [self.label mj_textWidth] / 2 - self.loading.mj_w, self.mj_h * 0.5);
}
- (void)setState:(MJRefreshState)state {
    MJRefreshCheckState;
//    self.label.textColor = [UIColor colorWithRed:254 / 255.0 green:59 / 255.0 blue:125 / 255.0 alpha:1.0];
    switch (state) {
        case MJRefreshStateIdle: {
            [self.loading stopAnimating];
            self.label.text = @"上拉加载更多";
        } break;
        case MJRefreshStatePulling: {
            [self.loading stopAnimating];
            self.label.text = @"松开加载更多";
        } break;
        case MJRefreshStateRefreshing: {
            [self.loading startAnimating];
            self.label.text = @"正在加载更多";
        } break;
        case MJRefreshStateNoMoreData: {
            [self.loading stopAnimating];
            self.label.text = self.xmState.length > 0 ? self.xmState : @"—— 我也是有底线的 ——";
        } break;
        default:
            break;
    }
}
@end
